package com.zyj.springboothapim.service.impl;

import com.zyj.springboothapim.bean.Parking;
import com.zyj.springboothapim.mapper.AdminMapper;
import com.zyj.springboothapim.mapper.ParkingMapper;
import com.zyj.springboothapim.service.ParkingService;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParkingServiceImpl implements ParkingService
{

    private ParkingMapper parkingMapper;

    @Autowired
    public void setParkingMapper(ParkingMapper parkingMapper){this.parkingMapper = parkingMapper;}

    //获取停车位所有信息
    @Override
    public List<Parking> selectParking()
    {
        return parkingMapper.selectParking();
    }

    //获取流动车位表static="流动"
    @Override
    public List<Parking> selectMobileparking()
    {
        return parkingMapper.selectMobileparking();
    }

    //获取车位安排表static="固定"且id!=null
    @Override
    public List<Parking> selectFixedParkingSpace()
    {
        return  parkingMapper.selectFixedParkingSpace();
    }


    //申请停车位
    @Override
    public String updataParking(Parking parking)
    {
        /*
        * 具体会在service实现查看车位是否被占用，若被占用就申请失败
        * success 申请成功
        * fall 申请失败
        * */
        Parking parking1 =  selectParkingByid(parking);
        if(parking1.isIfUsed() == false)
        {
            parking1.setIfUsed(true);
            parkingMapper.updataParking(parking1);
            return "success";//申请成功
        }
        else
        {
            return "fall";
        }

    }
    //通过停车位的id查找某个停车位
    @Override
    public Parking selectParkingByid(Parking parking)
    {
        return parkingMapper.selectParkingByid(parking);
    }


}
